package 开始的剑指offer8月.链表;
// https://leetcode-cn.com/problems/UHnkqh/
public class 剑指OfferII024反转链表0830 {

      public class ListNode {
          int val;
          ListNode next;
          ListNode() {}
          ListNode(int val) { this.val = val; }
          ListNode(int val, ListNode next) { this.val = val; this.next = next; }
      }

    class Solution {
          //思路是将各个的next反转即可current.next=prev然后一直移动  但是需要保存current.next  然后修改上一个节点为当前节点的值
        //当前节点的值为保存的next的值
        public ListNode reverseList(ListNode head) {
            ListNode next,prev=null;
            ListNode current=head;
            while(current!=null){
                next=current.next;
                current.next=prev;
                prev=current;
                current=next;
            }
            return prev;
        }
    }
}
/*
 //递归
            if(head==null||head.next==null)
            {
                return head;
            }
            ListNode p=reverseList(head.next);
            head.next.next=head;
            head.next=null;
            return p;
 */
